<?php echo $this->Form->create("discipline", array('style' => 'width: 100%;')) ?>
<div class="row-fluid">
    <div class="box paint color_24">
        <div class="title">
            <h4> <span><?php echo __('Weights'); ?></span> </h4>
        </div>
        <!-- End .title -->
<?php $tabsN = count($disciplines); ?>
        <div class="content">
        	<ul class="nav nav-tabs">
        		<?php for ($i=0; $i < $tabsN/15; $i++):?> 
        			<li <?php echo ($i == 0)?'class="active"':"" ?>><a href="#<?php echo $i ?>" data-toggle="tab" ><?php echo $i+1 ?></a></li>
        		<?php endfor; ?>
             </ul>
             <div class="tab-content">
                <?php for ($i=0; $i < $tabsN/15; $i++):?> 
                <div class="tab-pane fade <?php echo ($i == 0)?'in active':''?>" id="<?php echo $i ?>">
                	<table id="datatable" class="responsive table table-striped table-bordered" style="width:100%;margin-bottom:0; ">
		                <thead>
		                    <tr>
								<th><?php echo __('Name') ?></th>
								<th><?php echo __('Semester') ?></th>
								<th><?php echo __('Total workload') ?></th>
								<th><?php echo __('Theoretical workload') ?></th>
								<th><?php echo __('Practice workload') ?></th>
								<th><?php echo __('Team') ?></th>
								<th><?php echo __('Course') ?></th>
								<th><?php echo __('Choices') ?></th>
								<th><?php echo __('Weight') ?></th>
							</tr>
		                </thead>
		                <tbody>
		                    <?php for ($j = $i*15; $j < $i*15+15; $j++): ?>
		                    <?php if(isset($disciplines[$j])):?>
							<tr>
								<td><a data-toggle="modal" href="#<?php echo $disciplines[$j]['Discipline']['id'] ?>" style="color:#ffffff; text-decoration: underline"><?php echo $disciplines[$j]['Team']['name'] ?></a>&nbsp;</td>
								<td><?php echo h($disciplines[$j]['Discipline']['semester']); ?>&nbsp;</td>
								<td><?php echo h($disciplines[$j]['Discipline']['total_workload']); ?>&nbsp;</td>
								<td><?php echo h($disciplines[$j]['Discipline']['theoretical_workload']); ?>&nbsp;</td>
								<td><?php echo h($disciplines[$j]['Discipline']['practice_workload']); ?>&nbsp;</td>
								<td><?php echo h($disciplines[$j]['Discipline']['team']); ?>&nbsp;</td>
								<?php $courses = array(); ?>
			                    <?php foreach ($disciplines[$j]['Courses'] as $course) : 
			                        $courses[] = $course['acronym'];
			                    endforeach; ?>
			                    <td><?php echo implode(" + ", $courses) ?>&nbsp;</td>
								<?php if(isset($choices[$disciplines[$j]['Discipline']['id']])): ?>
									<td><?php echo h($choices[$disciplines[$j]['Discipline']['id']]); ?>&nbsp;</td>
								<?php else: ?>
									<td>0&nbsp;</td>
								<?php endif; ?>
								
								<td>
									
									<select name="<?php echo $disciplines[$j]['Discipline']['id'] ?>">
										<option value="0" <?php echo (isset($weights[$disciplines[$j]['Discipline']['id']]) && !$weights[$disciplines[$j]['Discipline']['id']])?"selected":"" ?>>0</option>
										<option value="1" <?php echo (isset($weights[$disciplines[$j]['Discipline']['id']]) && $weights[$disciplines[$j]['Discipline']['id']] == 1)?"selected":"" ?>>1</option>
										<option value="2" <?php echo (isset($weights[$disciplines[$j]['Discipline']['id']]) && $weights[$disciplines[$j]['Discipline']['id']] == 2)?"selected":"" ?>>2</option>
										<option value="3" <?php echo (isset($weights[$disciplines[$j]['Discipline']['id']]) && $weights[$disciplines[$j]['Discipline']['id']] == 3)?"selected":"" ?>>3</option>
										<option value="4" <?php echo (isset($weights[$disciplines[$j]['Discipline']['id']]) && $weights[$disciplines[$j]['Discipline']['id']] == 4)?"selected":"" ?>>4</option>
										<option value="5" <?php echo (isset($weights[$disciplines[$j]['Discipline']['id']]) && $weights[$disciplines[$j]['Discipline']['id']] == 5)?"selected":"" ?>>5</option>
										<option value="6" <?php echo (isset($weights[$disciplines[$j]['Discipline']['id']]) && $weights[$disciplines[$j]['Discipline']['id']] == 6)?"selected":"" ?>>6</option>
										<option value="7" <?php echo (isset($weights[$disciplines[$j]['Discipline']['id']]) && $weights[$disciplines[$j]['Discipline']['id']] == 7)?"selected":"" ?>>7</option>
										<option value="8" <?php echo (isset($weights[$disciplines[$j]['Discipline']['id']]) && $weights[$disciplines[$j]['Discipline']['id']] == 8)?"selected":"" ?>>8</option>
										<option value="9" <?php echo (isset($weights[$disciplines[$j]['Discipline']['id']]) && $weights[$disciplines[$j]['Discipline']['id']] == 9)?"selected":"" ?>>9</option>
										<option value="10" <?php echo (isset($weights[$disciplines[$j]['Discipline']['id']]) && $weights[$disciplines[$j]['Discipline']['id']] == 10)?"selected":"" ?>>10</option>
									</select>
									&nbsp;

								</td>
							</tr>
							<?endif;?>
							<?php endfor; ?>
		                </tbody>
            		</table>
                </div>
                <?php endfor; ?>
              </div>
            <div class="form-actions row-fluid">
                        <div class="span7 offset3">
                            <button type="submit" class="btn btn-primary"><?php echo __('Submit the choices') ?></button>
                        </div>
            </div>
			


        </div>
        <!-- End .content --> 
    </div>
    <!-- End box --> 
</div>
<!-- End .row-fluid -->
<?php foreach ($disciplines as $key => $discipline): ?>
  <div id="<?php echo $discipline['Discipline']['id'] ?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
      <h3 id="myModalLabel">Documentos</h3>
    </div>
    <div class="modal-body">
      <p><?php echo $this->Upload->view('Team', $discipline['Team']['id'], false, true); ?></p>
    </div>
    <div class="modal-footer">
      <button class="btn" data-dismiss="modal">Fechar</button>
    </div>
  </div>
<?php endforeach; ?>